﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO;
using WebClient;
namespace WebClient.admin.Modules.users
{
    public partial class AddNew : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.btnAddNew.Attributes.Add("onclick", "return OnSubmitClick();");
            this.btnCancel.Attributes.Add("onclick", "return ClearAll()");
            if (!this.IsPostBack) {
                LoadGroup();
            }
        }
        private void LoadGroup(){
            WebData db = new WebData();
            this.cbbgroupId.DataSource = db.GetAllUsergroups();
            this.cbbgroupId.DataTextField = "groupName";
            this.cbbgroupId.DataValueField = "id";
            this.cbbgroupId.DataBind();
        }

        private void AddNewItem()
        {
            WebData data = new WebData();
            Users item = new Users();
            int groupId = 2;
            try {
                groupId = Convert.ToInt32(cbbgroupId.SelectedValue);
            }
            catch { }
            //item.id = this.txtid.Text.Trim();
            item.userName = this.txtuserName.Text.Trim();
            item.fullName = this.txtfullName.Text.Trim();
            item.password = this.txtpassword.Text.Trim();
            item.email = this.txtemail.Text.Trim();
            item.create_on = DateTime.Now;            
            item.lastDate = DateTime.Now;
            item.status = 2;
            item.passDate = DateTime.Now;
            item.address = this.txtaddress.Text.Trim();
            item.phone = this.txtphone.Text.Trim();
            item.isActive = 1;
            item.groupID = groupId;
            item.birthDay = DateTime.Now;
            data.OnSubmitUsers(item, 0);
        }
        protected void btnAddNew_Click(object sender, EventArgs e)
        {
            AddNewItem();
        }
    }
}